/**
 * 预警人员配置personManagerList.js
 * 版本号： v1.0.0
 */
$(function(){
    $("#personManagerDg").datagrid({
        fit:true,
        fitColumns: true,
        method: "POST",
        rownumbers: true,
        singleSelect:true,
        striped:true,
        pagination: true,
        border:false,
        pageSize:25,
        pageList:[25],
        url: CONTEXT_PATH + '/message/personManagerList.do',
        idField: 'wpmId',
        frozenColumns:[[
            {field:'wpmId',checkbox:true}
        ]],
        columns: [
            [
                {field: 'temp1', title: '监测点名称', width: 300, align: 'center', fixed: true},
                {field: 'username', title: '预警人员', width: 120, align: 'center', fixed: true},
                {field: 'phone',  title: '预警手机号', width: 120, align: 'center', fixed: true},
                {field: 'createDate', title: '添加时间', width: 180, align: 'center', fixed: true}
            ]
        ],
        onLoadSuccess:function(data){
            if(data.rows.length > 0){
                $("#personManagerDg").datagrid("selectRow", 0);
            }
        }
    });

    //定义可操作按钮
    $("#personManagerMenu").datagrid({
        border:false,
        fit:true,
        toolbar:[{
            id:"warnEdit",
            text:"修改人员",
            iconCls:"icon-custom-edit",
            handler:function(){
                personManager_edit();
            }
        },"-",{
            id:"warnRefresh",
            text:"刷新消息",
            iconCls:"icon-custom-detail",
            handler:function(){
                personManager_refresh();
            }
        },"-"
        ]
    });

});





/**
 * 刷新消息
 */
function personManager_refresh(){
    $("#personManagerDg").datagrid("reload",{});
    $("#personManagerDg").datagrid("clearSelections");
}


/**
 * 修改预警
 * @returns {boolean}
 */
function personManager_edit(){
    var row = $("#personManagerDg").datagrid("getSelected");
    if(row == null){
        $.messager.show({ title:'操作提示', msg:"请选择修改监测点名称", timeout:3000, showType:"slide" });
        return;
    }
    $("#personManagerEdit_dialog").dialog({
        title: '修改人员',
        width: 400,
        modal: true,
        closed: true,
        height: 220,
        iconCls:"icon-custom-edit",
        buttons:[{
            text:"修改",
            iconCls:"icon-role-state-ok",
            handler:function(){
                doEditPersonManager();
            }
        },{
            text:"取消",
            iconCls:"icon-role-state-no",
            handler:function(){
                $('#personManagerEdit_dialog').dialog('close');
            }
        }]
    });

    $('#personManagerEdit_dialog').dialog('open');
    $("#personManagerEdit_dialog").dialog("move",{left:450,top:100});
    $("#personManagerEditForm").form("load", row);
}

/**
 * 执行修改预警
 */
function doEditPersonManager(){
    var params = $("#personManagerEditForm").serialize();
    $("#personManagerEditForm").form("submit",{
        cache:false,
        data: params,
        url: CONTEXT_PATH + "/message/editPersonManager.do",
        onSubmit:function() {
            return $(this).form("validate");
        },
        success:function(data) {
            var obj = JSON.parse(data);
            messager(obj);
            $('#personManagerEdit_dialog').dialog('close');
            $("#personManagerDg").datagrid("reload",{});
        }
    });
}
